package com.ticket.sass.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.admin.mapper.TakeTicketMapper;
import com.ticket.sass.admin.service.BaseService;
import com.ticket.sass.common.entity.tenant.TakeTicketEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ywb
 * @since 2024-05-07
 */
@Service
public class TakeTicketServiceImpl extends ServiceImpl<TakeTicketMapper, TakeTicketEntity> implements BaseService<TakeTicketEntity> {
    public Map<Long, List<TakeTicketEntity>> infoByOrderIds(List<Long> orderIds){
        if (orderIds.size() == 0){
            return new HashMap<>();
        }
      
        QueryWrapper<TakeTicketEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("order_id", orderIds);
        List<TakeTicketEntity> takeTickets = this.list(queryWrapper);
        
        // Grouping the tickets by orderId
        Map<Long, List<TakeTicketEntity>> ticketsByOrderId = new HashMap<>();
        for (TakeTicketEntity ticket : takeTickets) {
            ticketsByOrderId.computeIfAbsent(ticket.getOrderId(), k -> new ArrayList<>()).add(ticket);
        }
        
        return ticketsByOrderId;
    }
}
